package com.ydkfjs.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ydkfjs.common.Result;
import com.ydkfjs.model.dto.DailyRequest;
import com.ydkfjs.model.vo.DailyAllVO;
import com.ydkfjs.model.vo.DailyVO;
import com.ydkfjs.service.DailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: hb
 * @CreateTime: 2024-04-08 19:39
 * @Version: 1.0
 */
@Api(tags = "日常模块")
@RestController
@RequestMapping("/daily")
@Slf4j
public class DailyController {

    private final DailyService dailyService;
    public DailyController(DailyService dailyService) {
        this.dailyService = dailyService;
    }

    @ApiOperation("新增日常")
    @PostMapping("/add")
    public Result<?> add(@RequestBody DailyRequest dailyRequest) {
        dailyService.add(dailyRequest);
        return Result.success("新增成功");
    }

    @ApiOperation("根据日期查询记录")
    @GetMapping("/getByDate")
    public Result<?> getByDate(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate localDate) {
        DailyAllVO dailyAllVO = dailyService.getByData(localDate);
        return Result.success("获取成功", dailyAllVO);
    }

    @ApiOperation("根据id修改")
    @PutMapping("/updateById")
    public Result<?> updateById(@RequestParam Long id, @RequestBody DailyRequest dailyRequest) {
        dailyService.updateById(id, dailyRequest);
        return Result.success("修改成功");
    }

    @ApiOperation("根据id删除")
    @PutMapping("/deleteById")
    public Result<?> deleteById(@RequestParam Long id) {
        dailyService.deleteById(id);
        return Result.success("删除成功");
    }
}


